﻿using B.S.DataBase.MyProject.Domain.BOM;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using System.Collections.Generic;
using T.E.ERP.Read.API.Applicantions.Command.BomCOmmand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.BomConnamdHandler
{
    /// <summary>
    /// 查看操作记录
    /// 物联网-智能MES生产管理系统-01-BOM管理V1.1-20250206
    /// </summary>
    public class GetOperationRecordCommandHandler : IRequestHandler<GetOperationRecordCommand, APIResult<List<OperationRecord>>>
    {
        private readonly IBaseRepository<OperationRecord> operaRep;
        public GetOperationRecordCommandHandler(IBaseRepository<OperationRecord> operaRep) 
        { 
            this.operaRep = operaRep;
        }
        public Task<APIResult<List<OperationRecord>>> Handle(GetOperationRecordCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<OperationRecord>> result = new APIResult<List<OperationRecord>>();
            var list = operaRep.GetAll().Result;
            list = list.OrderByDescending(x => x.OId);
            result.Code = APIEnum.成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
